//
//  HSHomeWorkViewModal.swift
//  SchoolDemo
//
//  Created by rimi on 16/10/11.
//  Copyright © 2016年 YQ. All rights reserved.
//

import UIKit

typealias homoworkCallBack = (_ error : Error?,_ isRersh:Bool) -> ()

class HSHomeWorkViewModal {

    var homeWordArr: [HSHomeWorkModal] = []
    //请求数据
    func requestHomeData(finished:@escaping homoworkCallBack) {
        guard let key = userInfo ["key"] else {
            return
        }
        let id = 1
        //地址
        let url = "ZH-schoolname-S-getHomeworkBase"
        let parame = ["key":key,"id":id]
        
        HSNetWorkTools.shared.downloadData(url: url, parameters: parame) { (data, err) in
//            print(data,err)
            guard let data = data as? NSDictionary else {
                HSAlertView.bottomAlertView("网络连接失败，请确认您的网络")
                finished(err!,false)
                return
            }
            switch data["result"] as! Int {
            case 0:
                //字典转模型
                let dictArray = data["data"] as! [[String : Any]]
                
                var modalArray = [HSHomeWorkModal]()
                
                for dict in dictArray {
                   let homeWorkModel = HSHomeWorkModal(dict: dict)
                    modalArray.append(homeWorkModel)
                    
                }
                self.homeWordArr = modalArray
                //刷新
                finished(nil,true)
            case 1:
                HSAlertView.bottomAlertView("刷新完毕")
                finished(nil,false)
            default:
                break
            }
        }
    }
}
